<?php
/**
 *
 * PHP versions 4 and 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       cake
 * @subpackage    cake.cake.libs.view.templates.layouts
 * @since         CakePHP(tm) v 0.10.0.1076
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
?>
<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
	<?php echo $this->Html->charset(); ?>
	<title>
		<?php __('Dependence: No More'); ?>
		<?php echo $title_for_layout; ?>
	</title>
	
	<?php
	
		echo $this->Html->meta('icon');

		echo $this->Html->css('cake.generic');

		echo $scripts_for_layout;
	?>
	
	<meta name="viewport" content="width=device-width,initial-scale=1">
	
	<link href="/css/dependence.css" rel="stylesheet" type="text/css" />
	<script src="/js/libs/modernizr-2.0.6.min.js"></script>
	<link href='http://fonts.googleapis.com/css?family=Fjord+One|Oswald' rel='stylesheet' type='text/css'>
</head>
<body>
	<div id="container">
		<header class="topbar">
			<div class="topbar-inner">
				<div class="container-fluid">
					<img src="/img/dependenceV1.png" alt="Depencence no more" /><!--<?php echo $this->Html->link(__('Dependence: No More', true), '/feeds/view'); ?> -->
					<div id="user-nav">
            <?php
              if ($logged_in) {
                print "Welcome, <strong>" . $logged_in_user . '</strong> | ' . $html->link('Log Out', array('controller'=>'users','action'=>'logout'));
              } else {
                print $html->link('Log In', array('controller'=>'users','action'=>'login')) . ' -or- ' . $html->link('Register', array('controller'=>'users','action'=>'register'));
              }
            ?>
          </div>
				</div><!-- end container-fluid -->
			</div><!-- end topbar-inner -->
		</header><!-- end header -->
		<div id="content" role="main">
			
			
      
			
			<?php

					echo $this->Session->flash();
					//echo $this->Session->flash('auth');
			?>

      <?php if ($logged_in) { ?>
			
			
			
			
      
			<div class="sideBarNav">
				<h2>Actions</h2>
				<ul class="actionNav">
          <li><?php echo $html->link('Import Subscriptions', array('controller'=>'users','action'=>'import_opml')); ?></li>
          <li><?php echo $html->link('Purge Subscriptions', array('controller'=>'users','action'=>'purge_all')); ?></li>
					<li><?php echo $html->link('Add Subscription', array('#'), array('id' =>'addSubscription')); ?></li>
					<div class="subscribe" style="display: none;">
						<label for="feedURL">Feed URL:</label> <input type="text" id="feedURL" /><br/>
						<input type="button" id="doSubscribe" value="Subscribe" />
					</div>
          <!--
					
					by default you're always viewing now
					
					<li><?php echo $html->link('View Subscriptions', array('controller'=>'users','action'=>'view')); ?></li>
					
					-->
        </ul>
				
				<h2>Friends</h2>
				<ul class="friendsList">
					<?php
					foreach ($friends as $friend) {
						$friend = $friend['User'];
						$email_name = preg_replace('/^([^@\s]+)@.+?$/', '\1', $friend['email']);
						
						?><li><img src="http://www.gravatar.com/avatar/<?php echo md5(strtolower(trim($friend['email']))); ?>?s=16" alt="Gravatar" /> <a href="#<?php echo $friend['id']; ?>" alt="<?php echo $email_name; ?>" title="<?php echo $email_name; ?>"><?php echo htmlentities($friend['username']); ?></a></li>
						<?php
						
					}
					?>
				</ul>
				
				<h2>Subscriptions</h2>
				
			  <ul class="rootFolder">
				  <?php
					
					if (isset($user_obj)) {
						
						foreach ($feed_folders as $fldr) {
							$f = $fldr['Feedfolder'];
							?>
							<li class="feedfolder" id="feedfolder-<?php echo $f['id']; ?>">
								
								<a class="feedfolderLink" href="#<?php echo $f['id']; ?>"><span class="icon icon-folder"></span>&#xA0;<?php echo $f['label']; ?></a>
								<span class="unreadCount"></span>
								<ul class="subscriptionFolder">
										<?php
										
										foreach ($user_obj->Feedfolder->Feed->find('all', array('conditions'=>array('Feed.feedfolder_id'=>$f['id']), 'recursive'=>0)) as $key => $feed) {
											$feed = $feed['Feed'];
										
											?>
											<li class="feed" id="feedLink-<?php echo $feed['id']; ?>">
												<?php echo $html->link('<span class="icon icon-rss"></span>&#xA0;' . $feed['title'], array('controller'=>'feeds','action'=>'view',$feed['id']), array('class'=>'feedLink','title'=>$feed['xml'],'alt'=>$feed['xml'],'escape'=>false)); ?>
												<span class="unreadCount"></span>
											</li>
											<?php
										}
										?>
								</ul><!-- /.subscriptionFolder -->
							</li><!-- /.feedfolder -->
							<?php
							
						} // each folder
						
										
						foreach ($user_obj->Feedfolder->Feed->find('all', array('conditions'=>array('Feed.feedfolder_id'=>$dep->getRootFeedfolder($logged_in_id), 'Feedfolder.user_id'=>$logged_in_id), 'recursive'=>0)) as $key => $feed) {
							$feed = $feed['Feed'];
						
							?>
							<li class="feed" id="feedLink-<?php echo $feed['id']; ?>">
								<?php echo $html->link('<span class="icon icon-rss"></span>&#xA0;' . $feed['title'], array('controller'=>'feeds','action'=>'view',$feed['id']), array('class'=>'feedLink','title'=>$feed['xml'],'alt'=>$feed['xml'],'escape'=>false)); ?>
								<span class="unreadCount"></span>
							</li>
							<?php
						}
						
						
					} // user_obj?
					?>
					
						  
					
				</ul><!-- /.subscriptionFolder.rootFolder -->
			
			</div><!-- /.sideBarNav -->
			
			<?php } // logged in? ?>
			
      <div class="mainContent">
				
			<?php echo $content_for_layout; ?>

			</div><!-- /.mainContent -->
		</div>
		<footer id="footer">
			<?php
			//    echo $this->Html->link(
			//		$this->Html->image('cake.power.gif', array('alt'=> __('CakePHP: the rapid development php framework', true), 'border' => '0')),
			//		'http://www.cakephp.org/',
			//		array('target' => '_blank', 'escape' => false)
			//	);
			?>
		</footer>
	</div>
	
	<script type="text/html" id="tmpl_feedEntry_a">
	  <li class="feedEntry" id="entryID-<%=id%>">
	</script>
	<script type="text/html" id="tmpl_feedEntry">
	  <li class="feedEntry" id="entryID-<%=id%>">
			<h3><a href="<%=link%>" target="_blank"><%=title%></a></h3>
			<ul class="metaData">
				<li><strong>Date:</strong> <%=pub_date%></li>
				<%
				  if (author.length > 0) {
				%><li><strong>Author:</strong> <%=author%></li>
				<%
				}
				%>
			</ul>
			<div class="feedBody">
			  <%=description%>
			</div>
			<div class="entryControls">
				<input type="checkbox" class="keepUnread" val="<%=id%>" /> <a href="#">Keep Unread</a>  &nbsp;
				<span class="icon icon-emailFriend"></span> <a href="#" class="emailFriend">Email to a friend</a>  &nbsp;
				<span class="icon icon-share"></span> <a href="#" class="share">Share</a>  &nbsp;
				<span class="icon icon-shareWithNote"> </span> <a href="#" class="shareWithNote">Share with Note</a>
			</div>
		</li><!-- /.feedEntry -->
	</script><!-- /#tmpl_feedEntry -->
	
  <script src="//code.jquery.com/jquery-1.7.min.js"></script>
	<script>window.jQuery || document.write('<script src="/js/libs/jquery-1.7.min.js"><\/script>')</script>

  <!-- scripts concatenated and minified via build script -->
	<script defer src="/js/jquery.color.js"></script>
	<script defer src="/js/tmpl.js"></script>
	<script defer src="/js/date.format.js"></script>
  <script defer src="/js/plugins.js"></script>
  <script defer src="/js/script.js"></script>
  <!-- end scripts -->

	<?php /*echo $this->element('sql_dump'); /* */ ?>
</body>
</html>